<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use WP_Term_Query;

class WPTerm extends Model
{

    public static function get_terms_by_id($ids)
    {
        $args = array(
            'include' => $ids,
            'fields' => 'all',
        );
        return self::wp_query($args);
    }

    public  static function wp_query($args)
    {
        $term_query = new WP_Term_Query($args);
        return self::format_terms($term_query->terms);
    }

    public static function format_terms($terms)
    {
        $formatted_terms = [];
        foreach ($terms as $term) {
            $formatted_terms[] = [
                'id' => $term->term_id,
                'name' => $term->name,
                'slug' => $term->slug,
            ];
        }
        return $formatted_terms;
    }
}
